from pathlib import Path


#TODO : 转义问题

# MathJax 配置模板（修复分隔符识别）
HTML_TEMPLATE = """
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script>
    MathJax = {{
      tex: {{
        inlineMath: [['$', '$'], ['\\(', '\\)']],
        displayMath: [['$$', '$$'], ['\\[', '\\]']]
      }}
    }};
    </script>
    <script id="MathJax-script" src="third_party/mathjax/es5/tex-chtml-full.js"></script>
    <script src="third_party/mermaid/mermaid.min.js"></script>
    <script>mermaid.initialize({{startOnLoad: true, theme: 'dark', securityLevel: 'loose'}}); </script>
</head>
<body style="font-family: Arial; margin: 20px;">
  {}
</body>
</html>
"""

class MathFormat():

    @staticmethod
    def format(html):

        current_dir = Path(__file__).parent.absolute()

        # 构建本地 mermaid.js 路径
        mermaid_js_path = current_dir / "third_party" / "mermaid" / "mermaid.min.js"
        mermaid_js_path = mermaid_js_path.as_posix()  # 转换为字符串路径

        # 构建本地 MathJax 路径
        mathjax_js_path = current_dir / "third_party" / "mathjax" / "es5" / "tex-chtml-full.js"
        mathjax_js_path = mathjax_js_path.as_posix()  # 转换为字符串路径



        html = HTML_TEMPLATE.format(html)
        return html